home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mc51bugs.zip / Q32837 < prev    next >
Text File  |  1988-07-29  |  2KB  |  57 lines

  1. Q32837 Bad Code Generated when Accessing Data in the Code Segment
  2. C Compiler
  3. 5.10   | 5.10
  4. MS-DOS | OS/2
  5.  
  6. Summary:
  7.    The C compiler generates incorrect code for a program that accesses
  8. data in the code segment. It "forgets" that the data is in a far
  9. segment and tries to access it with a near (16-bit) pointer.
  10.    A workaround to the problem is to compile with the optimizer
  11. disabled (/Od).
  12.    Microsoft has confirmed this to be a problem in Version 5.10. We
  13. are researching this problem and will post new information as it
  14. becomes available.
  15.  
  16. More Information:
  17.    The following is the program that demonstrates the problem,
  18. along with the generated code; it is compiled in medium model:
  19.  
  20. extern void far SomeProc();
  21.  
  22. main()
  23.   {
  24.   typedef struct {
  25.     char patch;
  26.     } TEMPLATE;
  27.  
  28.   TEMPLATE far *lpSomeProc;
  29.  
  30.   lpSomeProc = (TEMPLATE far *)SomeProc; /* point pointer into code segment*/
  31.   lpSomeProc->patch = 123;        /* Bad code generated for this statement */
  32.   }                               /* when optimizer used */
  33.  
  34. /*
  35. ;BAD CODE:
  36. ; Line 11
  37. mov     WORD PTR [bp-4],OFFSET _SomeProc        ;lpSomeProc
  38. mov     WORD PTR [bp-2],SEG _SomeProc
  39. ; Line 12
  40. mov     BYTE PTR _SomeProc,123        <== THIS IS INCORRECT; A NEAR PTR
  41.  
  42.  
  43. ;GOOD CODE: (produced with -Od option)
  44. ; Line 11
  45.         mov     WORD PTR [bp-4],OFFSET _SomeProc        ;lpSomeProc
  46.         mov     WORD PTR [bp-2],SEG _SomeProc
  47. ; Line 12
  48.         les     bx,DWORD PTR [bp-4]     ;lpSomeProc
  49.         mov     BYTE PTR es:[bx],123      <== THIS IS CORRECT; A FAR PTR
  50. ; Line 13
  51. */
  52.  
  53.  
  54.  
  55. Keywords:  buglist5.10 tar78670
  56. Updated  88/07/29 12:16
  57.